/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    code: { type: String, _type: 'code', title: '编码', required: true },
    date: {
      type: Date, _type: 'date', title: '日期', required: true, enableArea: [ 'table'

      ]
    },
    salesman: {
      type: String, _type: 'string', title: '业务员', required: true, enableArea: [
        'table'
      ]
    },
    customerName: {
      type: String, _type: 'string', title: '客户名称', required: true, enableArea: [
        'table'
      ]
    },
    addr: {
      type: Array, _type: 'array', title: '地址',
      cols: [
        { type: String, _type: 'string',key:'addr', title: '地址' }
      ], enableArea: []
    },
    customerType: {
      type: String, _type: 'select', title: '客户类型', options: [ '终端', '经销商' ], required: true, enableArea: [
        'table'
      ]
    },

    contacts: {
      type: Array, _type: 'array', title: '联系人',
      cols: [
        { type: String, _type: 'string', title: '联系人', key: 'contacts' },
        { type: String, _type: 'string', title: '联系电话', key: 'phone' },
      ], enableArea: []
    },
    // phone: { type: String, _type: 'string', title: '联系电话' },

    usage: {
      type: Array, _type: 'array', title: '用量',
      cols: [
        { type: String, _type: 'string', title: '用量', key: 'usage' }
      ], enableArea: []
    },
    openMethod: {
      type: String,
      _type: 'select',
      title: '开发方式',
      options: [ '打电话', '陌拜', '先打电话后拜访', '先拜访后打电话' ],
      enableArea: [
        'table'
      ]
    },
    result: {
      type: Array, _type: 'array', title: '结果对策',
      cols: [
        { type: String, _type: 'string',key:'result', title: '结果' },
        { type: String, _type: 'string',key:'countermeasure', title: '对策' }
      ], enableArea: []
    },
    dealDate: { type: Date, _type: 'date', title: '成交日期',enableArea: [ 'table' ] },
    one: {
      type: Array, _type: 'array', title: '跟踪记录',
      cols: [
        { type: Date, _type: 'date', title: '日期',key:'data' },
        { type: String, _type: 'string', title: '方式',key:'method' },
        { type: String, _type: 'string', title: '结果',key:'result' },
        { type: String, _type: 'string', title: '对策',key:'countermeasure' },
      ], enableArea: []
    },
    // two: {
    //   type: Array, _type: 'array', title: '二次跟踪',
    //   cols: [
    //     { type: Date, _type: 'date', title: '日期',key:'twoData' },
    //     { type: String, _type: 'string', title: '方式',key:'twoMethod' },
    //     { type: String, _type: 'string', title: '结果',key:'twoResult' },
    //     { type: String, _type: 'string', title: '对策',key:'twoCountermeasure' },
    //   ], enableArea: []
    // },
    // three: {
    //   type: Array, _type: 'array', title: '三次跟踪',
    //   cols: [
    //     { type: Date, _type: 'date', title: '日期',key:'threeData' },
    //     { type: String, _type: 'string', title: '方式',key:'threeMethod' },
    //     { type: String, _type: 'string', title: '结果',key:'threeResult' },
    //     { type: String, _type: 'string', title: '对策',key:'threeCountermeasure' },
    //   ], enableArea: []
    // },
    memo: { type: String, _type: 'memo', title: '备注',  enableArea: [  ] },
    fileList: {
      type: Array, _type: 'fileList', title: '图片列表', enableArea: []
    },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('DicCustomer', _schema);
};
